package me.zhengjie.modules.system.rest;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.system.domain.SafeRiskItem;
import me.zhengjie.modules.system.service.SafeTestItemService;
import me.zhengjie.modules.system.vo.SafeRiskItemVo;
import org.springframework.data.repository.query.Param;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * SafeTestItemController
 *
 * @author guoyuan
 * @version 1.0.0
 * @since 1.0.0
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "安全规则：场景风险信息")
@RequestMapping("/api/safeTestItem")
public class SafeTestItemController {

    private final SafeTestItemService safeTestItemService;

    @ApiOperation("所有场景风险信息列表查询")
    @GetMapping
    @PreAuthorize("@el.check('testItem:list')")
    public ResponseEntity<Object> queryAll(@RequestBody SafeRiskItemVo vo) throws Exception {
        return new ResponseEntity<>(safeTestItemService.queryAll(vo), HttpStatus.OK);
    }
    @ApiOperation("通过TypeId查询详细信息")
    @PostMapping("/queryById")
    @PreAuthorize("@el.check('testItem:list')")
    public ResponseEntity<Object> queryByTypeId(@RequestParam("typeId") String typeId) throws Exception {
        return new ResponseEntity<>(safeTestItemService.queryByTypeId(typeId), HttpStatus.OK);
    }

    @ApiOperation("新增场景风险信息")
    @PostMapping("/create")
    @PreAuthorize("@el.check('testItem:create')")
    public ResponseEntity<Object> creat(@RequestBody SafeRiskItem entity) {
        safeTestItemService.create(entity);
        return new ResponseEntity<>( HttpStatus.OK);
    }

    @ApiOperation("更新场景风险信息")
    @PutMapping("/update")
    @PreAuthorize("@el.check('testItem:update')")
    public ResponseEntity<Object> update(@RequestBody SafeRiskItem entity) throws Exception {
        safeTestItemService.update(entity);
        return new ResponseEntity<>( HttpStatus.OK);
    }
    @ApiOperation("所有测试类型列表查询")
    @DeleteMapping("/delete")
    @PreAuthorize("@el.check('testItem:delete')")
    public ResponseEntity<Object> delete(SafeRiskItemVo vo) throws Exception {
        safeTestItemService.delete(vo.getId());
        return new ResponseEntity<>( HttpStatus.OK);
    }

}
